package com.ruoyi.web.controller.system;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ruoyi.web.controller.tool.JsonResult;
import com.ruoyi.web.controller.tool.PageInfo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.DeptYue;
import com.ruoyi.system.service.IDeptYueService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 单位余额Controller
 * 
 * @author zxl
 * @date 2023-07-05
 */
@Controller
@RequestMapping("/system/deptyue")
public class DeptYueController extends BaseController
{
    private String prefix = "system/deptyue";

    @Autowired
    private IDeptYueService deptYueService;

    @RequiresPermissions("system:deptyue:view")
    @GetMapping()
    public String deptyue()
    {
        return prefix + "/index";
    }

    /**
     * 查询单位余额列表
     */
    @RequiresPermissions("system:deptyue:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(DeptYue deptYue)
    {
        startPage();
        List<DeptYue> list = deptYueService.selectDeptYueList(deptYue);
        return getDataTable(list);
    }

    /**
     * 导出单位余额列表
     */
    @RequiresPermissions("system:deptyue:export")
    @Log(title = "单位余额", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(DeptYue deptYue)
    {
        List<DeptYue> list = deptYueService.selectDeptYueList(deptYue);
        ExcelUtil<DeptYue> util = new ExcelUtil<DeptYue>(DeptYue.class);
        return util.exportExcel(list, "单位余额数据");
    }

    /**
     * 新增单位余额
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存单位余额
     */
    @RequiresPermissions("system:deptyue:add")
    @Log(title = "单位余额", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(DeptYue deptYue)
    {
        return toAjax(deptYueService.insertDeptYue(deptYue));
    }

    /**
     * 修改单位余额
     */
    @RequiresPermissions("system:deptyue:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        DeptYue deptYue = deptYueService.selectDeptYueById(id);
        mmap.put("deptYue", deptYue);
        return prefix + "/edit";
    }

    /**
     * 修改保存单位余额
     */
    @RequiresPermissions("system:deptyue:edit")
    @Log(title = "单位余额", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(DeptYue deptYue)
    {
        return toAjax(deptYueService.updateDeptYue(deptYue));
    }

    /**
     * 删除单位余额
     */
    @RequiresPermissions("system:deptyue:remove")
    @Log(title = "单位余额", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(deptYueService.deleteDeptYueByIds(ids));
    }


    /**
     * 单位余额-列表
     */
    @PostMapping("/deptyuelist")
    @ResponseBody
    public JsonResult<Map<String, Object>> deptyuelist(String deptId,String jingfeipicimingcheng,int pageIndex,int pageSize)
    {
        List<Map<String, Object>> tuikuanList = deptYueService.selectTuiKuanList(deptId,jingfeipicimingcheng,
                pageIndex, pageSize);
        int count = deptYueService.countTuiKuanList(deptId,jingfeipicimingcheng);
        PageInfo pageInfo = new PageInfo(pageIndex, pageSize, count);
        Map<String, Object> result = new HashMap<>();
        result.put("pageInfo", pageInfo);
        result.put("yuelist", tuikuanList);
        return JsonResult.getSuccessResult(result);
    }
}
